package splug.cjk;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class BBSWrite extends Activity{

	private Button btn_write;
	private Button btn_cancel;
	private EditText ed_title;
	private EditText ed_content;

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.bbs_write);

		btn_write = (Button) findViewById(R.id.btn_content_ok);
		btn_cancel = (Button) findViewById(R.id.btn_content_cancel);
		ed_title = (EditText) findViewById(R.id.ed_bbs_title);
		ed_content = (EditText) findViewById(R.id.ed_bbs_write);

		btn_write.setOnClickListener(on_write);
		btn_cancel.setOnClickListener(on_cancel);
	}

	private View.OnClickListener on_write = new View.OnClickListener() {		
		@Override
		public void onClick(View v) {
			String title = ed_title.getText().toString();
			String content = ed_content.getText().toString();
			
			if(title.equals("")){
				Toast.makeText(BBSWrite.this, "제목을 입력해주세요.", Toast.LENGTH_SHORT).show();
			}
			else if(title.length() > 20){
				Toast.makeText(BBSWrite.this, "제목을 20자 이내로 작성해주세요", Toast.LENGTH_SHORT).show();
			}
			else if(content.length() > 200){
				Toast.makeText(BBSWrite.this, "내용을 200자 이내로 작성해주세요", Toast.LENGTH_SHORT).show();
			}
			else if(content.equals("")){
				Toast.makeText(BBSWrite.this, "내용을 입력해주세요", Toast.LENGTH_SHORT).show();
			}
			else{
				Intent intent = getIntent();
				intent.putExtra("CONTENT", content);
				intent.putExtra("TITLE", title);
				setResult(RESULT_OK, intent);
				finish();
			}
		}
	};

	private View.OnClickListener on_cancel = new View.OnClickListener() {		
		@Override
		public void onClick(View v) {
			finish();
		}
	};
}
